#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
	int score = 0;
	int width = 600;
	int hight = 800;
	initgraph(width, hight);//width,hight
	float x = 100;
	float r = 20;//radius
	float y = hight - r-500;
	float vy = 0;
	float g = 0.25;//grivity
	float width2 = 50;//rectangle start point
	float h = 200;
	float a = width-width2;
	float b = hight - h;
	float d = hight;
	float va = 2;//rectangle end point
	int n = 1;
	fillcircle(x, y, r);
	
	while (1)
	{
		if (_kbhit())//若“if(_kbhit())”:可在空中跳
		{
			char input = _getch();
			if (input == ' ')
			{
				vy = vy + 17;
			}
		}
		cleardevice();
		fillcircle(x, y, r);
		y = y - vy;
		vy = vy - g;
		fillrectangle(a, b, a+width2, d);
		fillrectangle(a, 0, a + width2, b-300);
		a = a - va;
		TCHAR s[20];//定义字符串数组
		swprintf_s(s, _T("%d"), score);//将score转换为字符串
		settextstyle(40, 0, _T("宋体"));//设置文字大小、字体
		outtextxy(50, 30, s);//输出得分文字
		Sleep(10);
		if (a <-50)
		{
			b = (rand() % 4 + 2) * 150;
			va = rand() / float(RAND_MAX) * 5 + 1.5;
			a = 600;
			score = score + 1;
		}
		if(((x+r)>=a)&& ((x - r) <= (a + width2))&& ((y + r) >= b))
		{
			score = 0;
		    Sleep(100);
		}
		if (((x + r) >= a) && ((x - r) <= (a + width2)) && ((y - r) <= b-300))
		{
			score = 0;
			Sleep(100);
		}
		
	}
	_getch();
	closegraph();
	return 0 ;
}